Fix _fast_cache invalidation bug in set_input and improve cache keys#448
Merged
MaxGhenis merged 1 commit intoPolicyEngine:masterfrom Mar 14, 2026
Merged
Conversation
set_input() was not clearing _fast_cache entries, causing stale values to be returned on subsequent calculate() calls. Also switches cache keys from str(period) to Period objects (already hashable tuples) to avoid unnecessary string conversions, deduplicates enum LUT and structured dtype unification logic in vectorial parameter lookups, and uses the public trace property instead of the private _trace attr. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #448 +/- ##
==========================================
+ Coverage 82.51% 82.79% +0.28%
==========================================
Files 202 203 +1
Lines 10634 10819 +185
Branches 1069 1096 +27
==========================================
+ Hits 8775 8958 +183
+ Misses 1583 1573 -10
- Partials 276 288 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
set_input()now invalidates_fast_cacheentries, preventing stale values from being returned by subsequentcalculate()callsPeriodobjects directly as_fast_cachekeys instead ofstr(period)—Periodis a hashable tuple subclass, so this avoids unnecessary string conversionstraceproperty (viagetattr) instead of private_traceattribute in the fast cache check_build_enum_lut()and_unify_structured_dtypes()helpers invectorial_parameter_node_at_instant.pyto eliminate 3x repeated dtype unification and 2x repeated enum LUT construction logic_fast_cachebehaviors (cache hit,set_inputinvalidation,delete_arraysinvalidation,cloneisolation,purge_cacheinvalidation, key type)Follows up on #436 (perf optimizations).
Test plan
tests/core/test_fast_cache.pywith 7 tests — all passset_inputinvalidation test FAILS before fix, PASSES after